home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / ear / mui23dev.lha / MUI / Developer / C / Examples / Settings.c < prev    next >
C/C++ Source or Header  |  1994-12-23  |  5KB  |  191 lines

  1. /*
  2. ** The Settings Demo shows how to load and save object contents.
  3. */
  4.  
  5. #include "demo.h"
  6.  
  7. #define ID_CANCEL 1
  8. #define ID_SAVE   2
  9. #define ID_USE    3
  10.  
  11. SAVEDS ASM VOID HelpFunc(REG(a2) Object *help,REG(a1) Object **objptr)
  12. {
  13.     LONG udata = NULL;
  14.     if (*objptr) get(*objptr,MUIA_UserData,&udata);
  15.     set(help,MUIA_Text_Contents,udata);
  16. }
  17.  
  18. int main(int argc,char *argv[])
  19. {
  20.     APTR app,window,str1,str2,str3,sl1,cy1,help,btsave,btuse,btcancel;
  21.     ULONG signals;
  22.     BOOL running = TRUE;
  23.     static char *sex[] = { "male", "female", NULL };
  24.     static struct Hook HelpHook = { {0,0}, (VOID *)HelpFunc, 0, 0 };
  25.  
  26.     init();
  27.  
  28.     app = ApplicationObject,
  29.         MUIA_Application_Title      , "Settings",
  30.         MUIA_Application_Version    , "$VER: Settings 10.12 (23.12.94)",
  31.         MUIA_Application_Copyright  , "©1992/93, Stefan Stuntz",
  32.         MUIA_Application_Author     , "Stefan Stuntz",
  33.         MUIA_Application_Description, "Show saving and loading of settings",
  34.         MUIA_Application_Base       , "SETTINGS",
  35.  
  36.         SubWindow, window = WindowObject,
  37.             MUIA_Window_Title, "Save/use me and start me again!",
  38.             MUIA_Window_ID   , MAKE_ID('S','E','T','T'),
  39.             MUIA_Window_NeedsMouseObject, TRUE,
  40.  
  41.             WindowContents, VGroup,
  42.  
  43.                 Child, ColGroup(2), GroupFrameT("User Identification"),
  44.                     Child, Label2("Name:"),
  45.                     Child, str1 = StringObject, StringFrame,
  46.                         MUIA_ExportID, 1,
  47.                         MUIA_UserData, "First and last name of user.",
  48.                         End,
  49.                     Child, Label2("Address:"),
  50.                     Child, str2 = StringObject, StringFrame,
  51.                         MUIA_ExportID, 2,
  52.                         MUIA_UserData, "Street, city and ZIP code." ,
  53.                         End,
  54.                     Child, Label1("Password:"),
  55.                     Child, str3 = StringObject, StringFrame,
  56.                         MUIA_ExportID, 4,
  57.                         MUIA_UserData, "Global access password (invisible).",
  58.                         MUIA_String_Secret, TRUE,
  59.                         End,
  60.                     Child, Label1("Sex:"),
  61.                     Child, cy1  = CycleObject,
  62.                         MUIA_ExportID, 6,
  63.                         MUIA_Cycle_Entries, sex,
  64.                         MUIA_UserData, "Guess what this means...",
  65.                         End,
  66.                     Child, Label("Age:"),
  67.                     Child, sl1  = SliderObject,
  68.                         MUIA_ExportID, 5,
  69.                         MUIA_Slider_Min, 9,
  70.                         MUIA_Slider_Max, 99,
  71.                         MUIA_UserData, "Several areas require a minimum age.",
  72.                         End,
  73.                     Child, Label1("Info:"),
  74.                     Child, help = TextObject, TextFrame,
  75.                         MUIA_UserData, "This is the info gadget.",
  76.                         End,
  77.                     End,
  78.  
  79.                 Child, VSpace(2),
  80.  
  81.                 Child, HGroup, MUIA_Group_SameSize, TRUE,
  82.                     Child, btsave   = SimpleButton("_Save"),
  83.                     Child, HSpace(0),
  84.                     Child, btuse    = SimpleButton("_Use"),
  85.                     Child, HSpace(0),
  86.                     Child, btcancel = SimpleButton("_Cancel"),
  87.                     End,
  88.  
  89.                 End,
  90.             End,
  91.         End;
  92.  
  93.     if (!app)
  94.         fail(app,"Failed to create Application.");
  95.  
  96.  
  97. /*
  98. ** Set Mouse Move Help Strings
  99. */
  100.  
  101.     DoMethod(window,MUIM_Notify,MUIA_Window_MouseObject,MUIV_EveryTime,
  102.         help,3,MUIM_CallHook,&HelpHook,MUIV_TriggerValue);
  103.  
  104.  
  105. /*
  106. ** Install notification events...
  107. */
  108.  
  109.     DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  110.         app,2,MUIM_Application_ReturnID,ID_CANCEL);
  111.  
  112.     DoMethod(btcancel,MUIM_Notify,MUIA_Pressed,FALSE,
  113.         app,2,MUIM_Application_ReturnID,ID_CANCEL);
  114.  
  115.     DoMethod(btsave,MUIM_Notify,MUIA_Pressed,FALSE,
  116.         app,2,MUIM_Application_ReturnID,ID_SAVE);
  117.  
  118.     DoMethod(btuse,MUIM_Notify,MUIA_Pressed,FALSE,
  119.         app,2,MUIM_Application_ReturnID,ID_USE);
  120.  
  121.  
  122. /*
  123. ** Cycle chain for keyboard control
  124. */
  125.  
  126.     DoMethod(window,MUIM_Window_SetCycleChain,
  127.         str1,str2,str3,cy1,sl1,btsave,btuse,btcancel,NULL);
  128.  
  129.  
  130. /*
  131. ** Concatenate strings, <return> will activate the next one
  132. */
  133.  
  134.     DoMethod(str1,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  135.         window,3,MUIM_Set,MUIA_Window_ActiveObject,str2);
  136.  
  137.     DoMethod(str2,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  138.         window,3,MUIM_Set,MUIA_Window_ActiveObject,str3);
  139.  
  140.     DoMethod(str3,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  141.         window,3,MUIM_Set,MUIA_Window_ActiveObject,str1);
  142.  
  143.  
  144. /*
  145. ** The application is set up, now load
  146. ** a previously saved configuration from env:
  147. */
  148.  
  149.     DoMethod(app,MUIM_Application_Load,MUIV_Application_Load_ENV);
  150.  
  151.  
  152.  
  153. /*
  154. ** Input loop...
  155. */
  156.  
  157.     set(window,MUIA_Window_Open,TRUE);
  158.     set(window,MUIA_Window_ActiveObject,str1);
  159.  
  160.     while (running)
  161.     {
  162.         switch (DoMethod(app,MUIM_Application_Input,&signals))
  163.         {
  164.             case MUIV_Application_ReturnID_Quit:
  165.             case ID_CANCEL:
  166.                 running = FALSE;
  167.                 break;
  168.  
  169.             case ID_SAVE:
  170.                 DoMethod(app,MUIM_Application_Save,MUIV_Application_Save_ENVARC);
  171.                 /* fall through */
  172.  
  173.             case ID_USE:
  174.                 DoMethod(app,MUIM_Application_Save,MUIV_Application_Save_ENV);
  175.                 running = FALSE;
  176.                 break;
  177.         }
  178.  
  179.         if (running && signals) Wait(signals);
  180.     }
  181.  
  182.     set(window,MUIA_Window_Open,FALSE);
  183.  
  184.  
  185. /*
  186. ** Shut down...
  187. */
  188.  
  189.     fail(app,NULL);
  190. }
  191.